// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        downDuration: 0.01,
        downHeight: -10
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // 初始化跳跃动作
        this.downAction = this.setDownAction();
        this.node.runAction(this.downAction);
    },

    start () {

    },

    update (dt) {
        // 判断红包雨是否落到了屏幕下，如果落到了屏幕下，则移出当前节点
        var rainY = this.node.y;
        var gameBottom = -1 * this.node.getParent().height/2;

        if (rainY <= gameBottom) {
            this.node.destroy();
        }
    },
    // 红包下落动画
    setDownAction: function () {
        // 跳跃上升
        var down = cc.moveBy(this.downDuration, cc.v2(0, this.downHeight)).easing(cc.easeCubicActionOut());
        // 不断重复
        return cc.repeatForever(cc.sequence(down,down));
    }
});
